package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.DevilLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;



    //添加购买记录
    @PostMapping("savePaidRecord")
    public Result savePaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo) {
        userInfoService.savePaidRecord(userPaidRecordVo);
        return Result.ok();
    }

    @GetMapping("isPaidAlbum/{albumId}/{userId}")
    Result<Boolean> isPaidAlbum(@PathVariable("albumId") Long albumId,
                                @PathVariable("userId") Long userId) {
        Boolean flag = userInfoService.isPaidAlbum(albumId,userId);
        return Result.ok(flag);
    }

    /**
     * 判断用户是否购买声音列表
     * @param albumId
     * @param trackIdList
     * @return
     */
    @DevilLogin(required = false)
    @Operation(summary = "判断用户是否购买声音列表")
    @PostMapping("userIsPaidTrack/{userId}/{albumId}")
    Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable("userId") Long userId,
                                               @PathVariable("albumId") Long albumId,
                                               @RequestBody List<Long> trackIdList) {
        Map<Long, Integer> map = userInfoService.userIsPaidTrack(userId, albumId, trackIdList);
        //	返回map 集合数据
        return Result.ok(map);
    }

    //根据用户id获取用户信息
    @Operation(summary = "根据用户id获取用户信息")
    @GetMapping("getUserInfoVo/{userId}")
    public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId) {
        UserInfoVo userInfo = userInfoService.getUserInfo(userId);
        return Result.ok(userInfo);
    }

    /**
     * 根据专辑Id 获取到用户已支付声音Id列表
     * @param albumId
     * @return
     */
    @DevilLogin
    @Operation(summary = "根据专辑id获取用户支付过的声音id列表")
    @GetMapping("findUserPaidTrackList/{albumId}")
    public Result findUserPaidTrackList(@PathVariable Long albumId){
        Long userId = AuthContextHolder.getUserId();

        List<Long> idList = userInfoService.findUserPaidTrackList(userId,albumId);
        return Result.ok(idList);
    }

}

